package com.hwqsdk.myapplication.practise;

import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;

import org.jetbrains.annotations.NotNull;

/**
 * Create by Fanketly on 2021/11/24
 * Gitee:https://gitee.com/fanketly
 */
/*
             BaseAd<News, RvNewsItemBinding> newsAdapter = new BaseAd<>(R.layout.rv_news_item, BR.news);
        newsAdapter.setD(holder -> {
            RvNewsItemBinding dataBinding = holder.getDataBinding();
            dataBinding.tvRvItemNewsDate.setText("666");
        });
     b.rvNews.setAdapter(newsAdapter);
                    newsAdapter.setNewInstance(homeViewModel.getNewsList());
                    newsAdapter.setOnItemClickListener((adapter, view12, position) -> {
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("html", homeViewModel.getContent(position));
                        jump(NewsXqFragment.class, bundle, "news");
                    });*/
public class DataRvAd<T, BD extends ViewDataBinding> extends BaseQuickAdapter<T, BaseDataBindingHolder<BD>> {
    private final int varId;

    public DataRvAd(int layoutResId, int varId) {
        super(layoutResId);
        this.varId = varId;
    }

    private D<BD> d;

    public void setD(D<BD> d) {
        this.d = d;
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<BD> bdBaseDataBindingHolder, T t) {
        BD dataBinding = bdBaseDataBindingHolder.getDataBinding();
        if (dataBinding != null) {
            dataBinding.setVariable(varId, t);
            dataBinding.executePendingBindings();
            d.doSomething(bdBaseDataBindingHolder);
        }
    }

    public interface D<BD extends ViewDataBinding> {
        void doSomething(BaseDataBindingHolder<BD> holder);
    }
}
